package com.vlyman.base.service.impl;

import com.vlyman.base.mapper.UserMapper;
import com.vlyman.base.model.entity.User;
import com.vlyman.base.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * 类描述：
 *  user业务实现类
 * @author chenjs
 * @date 2018/9/15
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    /**
     * 方法描述：
     * 获取全部用户
     *
     * @exception Exception 业务层不处理异常，统一将异常向上一层抛
     * @return List<User>
     * @author chenjs
     * @date 2018/9/15
     */
    @Override
    public List<User> getAllUser() {
        return userMapper.selectList(null);
    }

    /**
     * 方法描述：
     * 保存用户
     *
     * @exception Exception 业务层不处理异常，统一将异常向上一层抛
     * @param user
     * @return String
     * @author chenjs
     * @date 2018/9/17
     */
    @Override
    public String saveUser(User user){
        userMapper.insert(user);
        if (!StringUtils.isEmpty(user.getName().trim())) {
            throw new RuntimeException("测试失败回滚！");
        }
        return "success";
    }
}
